home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / src / RCS / main.c,v < prev    next >
Encoding:
Text File  |  1991-08-06  |  54.0 KB  |  2,804 lines

  1. head    5.29;
  2. branch    5.29.0;
  3. access;
  4. symbols
  5.     RELEASE:5.29.0.33
  6.     BETA:5.29.0.30
  7.     UICSO:5.29.0
  8.     VANILLA:5.29;
  9. locks; strict;
  10. comment    @ * @;
  11.  
  12.  
  13. 5.29
  14. date    90.06.20.08.36.02;    author paul;    state Exp;
  15. branches
  16.     5.29.0.1;
  17. next    ;
  18.  
  19. 5.29.0.1
  20. date    90.06.20.09.43.09;    author paul;    state Exp;
  21. branches;
  22. next    5.29.0.2;
  23.  
  24. 5.29.0.2
  25. date    90.06.25.09.20.57;    author paul;    state Exp;
  26. branches;
  27. next    5.29.0.3;
  28.  
  29. 5.29.0.3
  30. date    90.07.08.17.46.26;    author paul;    state Exp;
  31. branches;
  32. next    5.29.0.4;
  33.  
  34. 5.29.0.4
  35. date    90.07.12.08.01.34;    author paul;    state Exp;
  36. branches;
  37. next    5.29.0.5;
  38.  
  39. 5.29.0.5
  40. date    90.08.27.17.15.45;    author paul;    state Exp;
  41. branches;
  42. next    5.29.0.6;
  43.  
  44. 5.29.0.6
  45. date    90.09.21.14.48.32;    author paul;    state Exp;
  46. branches;
  47. next    5.29.0.7;
  48.  
  49. 5.29.0.7
  50. date    90.10.01.23.07.21;    author paul;    state Exp;
  51. branches;
  52. next    5.29.0.8;
  53.  
  54. 5.29.0.8
  55. date    90.10.13.18.42.53;    author paul;    state Exp;
  56. branches;
  57. next    5.29.0.9;
  58.  
  59. 5.29.0.9
  60. date    90.10.16.22.49.27;    author paul;    state Exp;
  61. branches;
  62. next    5.29.0.10;
  63.  
  64. 5.29.0.10
  65. date    90.10.25.20.19.27;    author paul;    state Exp;
  66. branches;
  67. next    5.29.0.11;
  68.  
  69. 5.29.0.11
  70. date    90.11.01.16.45.01;    author paul;    state Exp;
  71. branches;
  72. next    5.29.0.12;
  73.  
  74. 5.29.0.12
  75. date    90.11.07.13.55.16;    author paul;    state Exp;
  76. branches;
  77. next    5.29.0.13;
  78.  
  79. 5.29.0.13
  80. date    90.11.11.10.37.03;    author paul;    state Exp;
  81. branches;
  82. next    5.29.0.14;
  83.  
  84. 5.29.0.14
  85. date    90.11.13.15.29.28;    author paul;    state Exp;
  86. branches;
  87. next    5.29.0.15;
  88.  
  89. 5.29.0.15
  90. date    90.11.29.13.59.43;    author paul;    state Exp;
  91. branches;
  92. next    5.29.0.16;
  93.  
  94. 5.29.0.16
  95. date    90.12.18.14.57.22;    author paul;    state Exp;
  96. branches;
  97. next    5.29.0.17;
  98.  
  99. 5.29.0.17
  100. date    90.12.21.23.52.24;    author paul;    state Exp;
  101. branches;
  102. next    5.29.0.18;
  103.  
  104. 5.29.0.18
  105. date    91.01.19.19.26.02;    author paul;    state Exp;
  106. branches;
  107. next    5.29.0.19;
  108.  
  109. 5.29.0.19
  110. date    91.02.15.20.20.13;    author paul;    state Exp;
  111. branches;
  112. next    5.29.0.20;
  113.  
  114. 5.29.0.20
  115. date    91.02.17.04.30.19;    author paul;    state Exp;
  116. branches;
  117. next    5.29.0.21;
  118.  
  119. 5.29.0.21
  120. date    91.03.06.15.17.14;    author paul;    state Exp;
  121. branches;
  122. next    5.29.0.22;
  123.  
  124. 5.29.0.22
  125. date    91.03.26.21.42.54;    author paul;    state Exp;
  126. branches;
  127. next    5.29.0.23;
  128.  
  129. 5.29.0.23
  130. date    91.04.02.23.12.16;    author paul;    state Exp;
  131. branches;
  132. next    5.29.0.24;
  133.  
  134. 5.29.0.24
  135. date    91.04.05.06.33.33;    author paul;    state Exp;
  136. branches;
  137. next    5.29.0.25;
  138.  
  139. 5.29.0.25
  140. date    91.04.05.14.55.15;    author paul;    state Exp;
  141. branches;
  142. next    5.29.0.26;
  143.  
  144. 5.29.0.26
  145. date    91.04.11.15.11.47;    author paul;    state Exp;
  146. branches;
  147. next    5.29.0.27;
  148.  
  149. 5.29.0.27
  150. date    91.05.18.17.30.34;    author paul;    state Exp;
  151. branches;
  152. next    5.29.0.28;
  153.  
  154. 5.29.0.28
  155. date    91.05.23.21.39.05;    author paul;    state Exp;
  156. branches;
  157. next    5.29.0.29;
  158.  
  159. 5.29.0.29
  160. date    91.05.24.22.35.24;    author paul;    state Exp;
  161. branches;
  162. next    5.29.0.30;
  163.  
  164. 5.29.0.30
  165. date    91.06.02.03.38.40;    author paul;    state Exp;
  166. branches;
  167. next    5.29.0.31;
  168.  
  169. 5.29.0.31
  170. date    91.06.13.20.18.58;    author paul;    state Exp;
  171. branches;
  172. next    5.29.0.32;
  173.  
  174. 5.29.0.32
  175. date    91.06.21.13.58.10;    author paul;    state Exp;
  176. branches;
  177. next    5.29.0.33;
  178.  
  179. 5.29.0.33
  180. date    91.06.25.05.25.13;    author paul;    state Exp;
  181. branches;
  182. next    5.29.0.34;
  183.  
  184. 5.29.0.34
  185. date    91.06.27.14.24.13;    author paul;    state Exp;
  186. branches;
  187. next    5.29.0.35;
  188.  
  189. 5.29.0.35
  190. date    91.08.05.22.12.40;    author paul;    state Exp;
  191. branches;
  192. next    5.29.0.36;
  193.  
  194. 5.29.0.36
  195. date    91.08.06.18.17.12;    author paul;    state Exp;
  196. branches;
  197. next    ;
  198.  
  199.  
  200. desc
  201. @@
  202.  
  203.  
  204. 5.29
  205. log
  206. @5.64 Berkeley release
  207. @
  208. text
  209. @/*
  210.  * Copyright (c) 1983 Eric P. Allman
  211.  * Copyright (c) 1988 Regents of the University of California.
  212.  * All rights reserved.
  213.  *
  214.  * Redistribution and use in source and binary forms are permitted provided
  215.  * that: (1) source distributions retain this entire copyright notice and
  216.  * comment, and (2) distributions including binaries display the following
  217.  * acknowledgement:  ``This product includes software developed by the
  218.  * University of California, Berkeley and its contributors'' in the
  219.  * documentation or other materials provided with the distribution and in
  220.  * all advertising materials mentioning features or use of this software.
  221.  * Neither the name of the University nor the names of its contributors may
  222.  * be used to endorse or promote products derived from this software without
  223.  * specific prior written permission.
  224.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  225.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  226.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  227.  */
  228.  
  229. #ifndef lint
  230. char copyright[] =
  231. "@@(#) Copyright (c) 1988 Regents of the University of California.\n\
  232.  All rights reserved.\n";
  233. #endif /* not lint */
  234.  
  235. #ifndef lint
  236. static char sccsid[] = "@@(#)main.c    5.29 (Berkeley) 6/1/90";
  237. #endif /* not lint */
  238.  
  239. #define    _DEFINE
  240.  
  241. #include <sys/file.h>
  242. #include <signal.h>
  243. #include <sgtty.h>
  244. #include "sendmail.h"
  245. #include <arpa/nameser.h>
  246. #include <resolv.h>
  247.  
  248. # ifdef lint
  249. char    edata, end;
  250. # endif lint
  251.  
  252. /*
  253. **  SENDMAIL -- Post mail to a set of destinations.
  254. **
  255. **    This is the basic mail router.  All user mail programs should
  256. **    call this routine to actually deliver mail.  Sendmail in
  257. **    turn calls a bunch of mail servers that do the real work of
  258. **    delivering the mail.
  259. **
  260. **    Sendmail is driven by tables read in from /usr/lib/sendmail.cf
  261. **    (read by readcf.c).  Some more static configuration info,
  262. **    including some code that you may want to tailor for your
  263. **    installation, is in conf.c.  You may also want to touch
  264. **    daemon.c (if you have some other IPC mechanism), acct.c
  265. **    (to change your accounting), names.c (to adjust the name
  266. **    server mechanism).
  267. **
  268. **    Usage:
  269. **        /usr/lib/sendmail [flags] addr ...
  270. **
  271. **        See the associated documentation for details.
  272. **
  273. **    Author:
  274. **        Eric Allman, UCB/INGRES (until 10/81)
  275. **                 Britton-Lee, Inc., purveyors of fine
  276. **                database computers (from 11/81)
  277. **        The support of the INGRES Project and Britton-Lee is
  278. **            gratefully acknowledged.  Britton-Lee in
  279. **            particular had absolutely nothing to gain from
  280. **            my involvement in this project.
  281. */
  282.  
  283.  
  284. int        NextMailer;    /* "free" index into Mailer struct */
  285. char        *FullName;    /* sender's full name */
  286. ENVELOPE    BlankEnvelope;    /* a "blank" envelope */
  287. ENVELOPE    MainEnvelope;    /* the envelope around the basic letter */
  288. ADDRESS        NullAddress =    /* a null address */
  289.         { "", "", "" };
  290.  
  291. /*
  292. **  Pointers for setproctitle.
  293. **    This allows "ps" listings to give more useful information.
  294. **    These must be kept out of BSS for frozen configuration files
  295. **        to work.
  296. */
  297.  
  298. # ifdef SETPROCTITLE
  299. char        **Argv = NULL;        /* pointer to argument vector */
  300. char        *LastArgv = NULL;    /* end of argv */
  301. # endif SETPROCTITLE
  302.  
  303. #ifdef DAEMON
  304. #ifndef SMTP
  305. ERROR %%%%   Cannot have daemon mode without SMTP   %%%% ERROR
  306. #endif SMTP
  307. #endif DAEMON
  308.  
  309. main(argc, argv, envp)
  310.     int argc;
  311.     char **argv;
  312.     char **envp;
  313. {
  314.     register char *p;
  315.     char **av;
  316.     extern int finis();
  317.     extern char Version[];
  318.     char *from;
  319.     typedef int (*fnptr)();
  320.     STAB *st;
  321.     register int i;
  322.     bool readconfig = TRUE;
  323.     bool queuemode = FALSE;        /* process queue requests */
  324.     bool nothaw;
  325.     static bool reenter = FALSE;
  326.     char jbuf[30];            /* holds MyHostName */
  327.     extern bool safefile();
  328.     extern time_t convtime();
  329.     extern putheader(), putbody();
  330.     extern ENVELOPE *newenvelope();
  331.     extern intsig();
  332.     extern char **myhostname();
  333.     extern char *arpadate();
  334.     extern char **environ;
  335.  
  336.     /*
  337.     **  Check to see if we reentered.
  338.     **    This would normally happen if e_putheader or e_putbody
  339.     **    were NULL when invoked.
  340.     */
  341.  
  342.     if (reenter)
  343.     {
  344.         syserr("main: reentered!");
  345.         abort();
  346.     }
  347.     reenter = TRUE;
  348.  
  349.     /* Enforce use of local time */
  350.     unsetenv("TZ");
  351.  
  352.     /*
  353.     **  Be sure we have enough file descriptors.
  354.     **    But also be sure that 0, 1, & 2 are open.
  355.     */
  356.  
  357.     i = open("/dev/null", O_RDWR);
  358.     while (i >= 0 && i < 2)
  359.         i = dup(i);
  360.     for (i = getdtablesize(); i > 2; --i)
  361.         (void) close(i);
  362.     errno = 0;
  363.  
  364. #ifdef LOG_MAIL
  365.     openlog("sendmail", LOG_PID, LOG_MAIL);
  366. #else 
  367.     openlog("sendmail", LOG_PID);
  368. #endif 
  369.  
  370.     /*
  371.     **  Set default values for variables.
  372.     **    These cannot be in initialized data space.
  373.     */
  374.  
  375.     setdefaults();
  376.  
  377.     /* set up the blank envelope */
  378.     BlankEnvelope.e_puthdr = putheader;
  379.     BlankEnvelope.e_putbody = putbody;
  380.     BlankEnvelope.e_xfp = NULL;
  381.     STRUCTCOPY(NullAddress, BlankEnvelope.e_from);
  382.     CurEnv = &BlankEnvelope;
  383.     STRUCTCOPY(NullAddress, MainEnvelope.e_from);
  384.  
  385.     /*
  386.     **  Do a quick prescan of the argument list.
  387.     **    We do this to find out if we can potentially thaw the
  388.     **    configuration file.  If not, we do the thaw now so that
  389.     **    the argument processing applies to this run rather than
  390.     **    to the run that froze the configuration.
  391.     */
  392.  
  393.     argv[argc] = NULL;
  394.     av = argv;
  395.     nothaw = FALSE;
  396.     while ((p = *++av) != NULL)
  397.     {
  398.         if (strncmp(p, "-C", 2) == 0)
  399.         {
  400.             ConfFile = &p[2];
  401.             if (ConfFile[0] == '\0')
  402.                 ConfFile = "sendmail.cf";
  403.             (void) setgid(getrgid());
  404.             (void) setuid(getruid());
  405.             nothaw = TRUE;
  406.         }
  407.         else if (strncmp(p, "-bz", 3) == 0)
  408.             nothaw = TRUE;
  409.         else if (strncmp(p, "-d", 2) == 0)
  410.         {
  411.             tTsetup(tTdvect, sizeof tTdvect, "0-99.1");
  412.             tTflag(&p[2]);
  413.             setbuf(stdout, (char *) NULL);
  414.             printf("Version %s\n", Version);
  415.         }
  416.     }
  417.  
  418.     InChannel = stdin;
  419.     OutChannel = stdout;
  420.  
  421.     if (!nothaw)
  422.         readconfig = !thaw(FreezeFile);
  423.  
  424.     /* reset the environment after the thaw */
  425.     for (i = 0; i < MAXUSERENVIRON && envp[i] != NULL; i++)
  426.         UserEnviron[i] = newstr(envp[i]);
  427.     UserEnviron[i] = NULL;
  428.     environ = UserEnviron;
  429.  
  430. # ifdef SETPROCTITLE
  431.     /*
  432.     **  Save start and extent of argv for setproctitle.
  433.     */
  434.  
  435.     Argv = argv;
  436.     if (i > 0)
  437.         LastArgv = envp[i - 1] + strlen(envp[i - 1]);
  438.     else
  439.         LastArgv = argv[argc - 1] + strlen(argv[argc - 1]);
  440. # endif SETPROCTITLE
  441.  
  442.     if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  443.         (void) signal(SIGINT, intsig);
  444.     if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
  445.         (void) signal(SIGHUP, intsig);
  446.     (void) signal(SIGTERM, intsig);
  447.     (void) signal(SIGPIPE, SIG_IGN);
  448.     OldUmask = umask(0);
  449.     OpMode = MD_DELIVER;
  450.     MotherPid = getpid();
  451.     FullName = getenv("NAME");
  452.  
  453.     errno = 0;
  454.     from = NULL;
  455.  
  456.     if (readconfig)
  457.     {
  458.         /* initialize some macros, etc. */
  459.         initmacros();
  460.  
  461.         /* hostname */
  462.         av = myhostname(jbuf, sizeof jbuf);
  463.         if (jbuf[0] != '\0')
  464.         {
  465.             if (tTd(0, 4))
  466.                 printf("canonical name: %s\n", jbuf);
  467.             p = newstr(jbuf);
  468.             define('w', p, CurEnv);
  469.             setclass('w', p);
  470.         }
  471.         while (av != NULL && *av != NULL)
  472.         {
  473.             if (tTd(0, 4))
  474.                 printf("\ta.k.a.: %s\n", *av);
  475.             setclass('w', *av++);
  476.         }
  477.  
  478.         /* version */
  479.         define('v', Version, CurEnv);
  480.     }
  481.  
  482.     /* current time */
  483.     define('b', arpadate((char *) NULL), CurEnv);
  484.  
  485.     /*
  486.     ** Crack argv.
  487.     */
  488.  
  489.     av = argv;
  490.     p = rindex(*av, '/');
  491.     if (p++ == NULL)
  492.         p = *av;
  493.     if (strcmp(p, "newaliases") == 0)
  494.         OpMode = MD_INITALIAS;
  495.     else if (strcmp(p, "mailq") == 0)
  496.         OpMode = MD_PRINT;
  497.     else if (strcmp(p, "smtpd") == 0)
  498.         OpMode = MD_DAEMON;
  499.     while ((p = *++av) != NULL && p[0] == '-')
  500.     {
  501.         switch (p[1])
  502.         {
  503.           case 'b':    /* operations mode */
  504.             switch (p[2])
  505.             {
  506.               case MD_DAEMON:
  507. # ifdef DAEMON
  508.                 if (getuid() != 0) {
  509.                     usrerr("Permission denied");
  510.                     exit (EX_USAGE);
  511.                 }
  512.                 (void) unsetenv("HOSTALIASES");
  513. # else
  514.                 usrerr("Daemon mode not implemented");
  515.                 ExitStat = EX_USAGE;
  516.                 break;
  517. # endif DAEMON
  518.               case MD_SMTP:
  519. # ifndef SMTP
  520.                 usrerr("I don't speak SMTP");
  521.                 ExitStat = EX_USAGE;
  522.                 break;
  523. # endif SMTP
  524.               case MD_ARPAFTP:
  525.               case MD_DELIVER:
  526.               case MD_VERIFY:
  527.               case MD_TEST:
  528.               case MD_INITALIAS:
  529.               case MD_PRINT:
  530.               case MD_FREEZE:
  531.                 OpMode = p[2];
  532.                 break;
  533.  
  534.               default:
  535.                 usrerr("Invalid operation mode %c", p[2]);
  536.                 ExitStat = EX_USAGE;
  537.                 break;
  538.             }
  539.             break;
  540.  
  541.           case 'C':    /* select configuration file (already done) */
  542.             break;
  543.  
  544.           case 'd':    /* debugging -- redo in case frozen */
  545.             tTsetup(tTdvect, sizeof tTdvect, "0-99.1");
  546.             tTflag(&p[2]);
  547.             setbuf(stdout, (char *) NULL);
  548. #ifdef NAMED_BIND
  549.             _res.options |= RES_DEBUG;
  550. #endif
  551.             break;
  552.  
  553.           case 'f':    /* from address */
  554.           case 'r':    /* obsolete -f flag */
  555.             p += 2;
  556.             if (*p == '\0' && ((p = *++av) == NULL || *p == '-'))
  557.             {
  558.                 p = *++av;
  559.                 if (p == NULL || *p == '-')
  560.                 {
  561.                     usrerr("No \"from\" person");
  562.                     ExitStat = EX_USAGE;
  563.                     av--;
  564.                     break;
  565.                 }
  566.             }
  567.             if (from != NULL)
  568.             {
  569.                 usrerr("More than one \"from\" person");
  570.                 ExitStat = EX_USAGE;
  571.                 break;
  572.             }
  573.             from = newstr(p);
  574.             break;
  575.  
  576.           case 'F':    /* set full name */
  577.             p += 2;
  578.             if (*p == '\0' && ((p = *++av) == NULL || *p == '-'))
  579.             {
  580.                 usrerr("Bad -F flag");
  581.                 ExitStat = EX_USAGE;
  582.                 av--;
  583.                 break;
  584.             }
  585.             FullName = newstr(p);
  586.             break;
  587.  
  588.           case 'h':    /* hop count */
  589.             p += 2;
  590.             if (*p == '\0' && ((p = *++av) == NULL || !isdigit(*p)))
  591.             {
  592.                 usrerr("Bad hop count (%s)", p);
  593.                 ExitStat = EX_USAGE;
  594.                 av--;
  595.                 break;
  596.             }
  597.             CurEnv->e_hopcount = atoi(p);
  598.             break;
  599.         
  600.           case 'n':    /* don't alias */
  601.             NoAlias = TRUE;
  602.             break;
  603.  
  604.           case 'o':    /* set option */
  605.             setoption(p[2], &p[3], FALSE, TRUE);
  606.             break;
  607.  
  608.           case 'q':    /* run queue files at intervals */
  609. # ifdef QUEUE
  610.             if (getuid() != 0) {
  611.                 usrerr("Permission denied");
  612.                 exit (EX_USAGE);
  613.             }
  614.             (void) unsetenv("HOSTALIASES");
  615.             queuemode = TRUE;
  616.             QueueIntvl = convtime(&p[2]);
  617. # else QUEUE
  618.             usrerr("I don't know about queues");
  619.             ExitStat = EX_USAGE;
  620. # endif QUEUE
  621.             break;
  622.  
  623.           case 't':    /* read recipients from message */
  624.             GrabTo = TRUE;
  625.             break;
  626.  
  627.             /* compatibility flags */
  628.           case 'c':    /* connect to non-local mailers */
  629.           case 'e':    /* error message disposition */
  630.           case 'i':    /* don't let dot stop me */
  631.           case 'm':    /* send to me too */
  632.           case 'T':    /* set timeout interval */
  633.           case 'v':    /* give blow-by-blow description */
  634.             setoption(p[1], &p[2], FALSE, TRUE);
  635.             break;
  636.  
  637.           case 's':    /* save From lines in headers */
  638.             setoption('f', &p[2], FALSE, TRUE);
  639.             break;
  640.  
  641. # ifdef DBM
  642.           case 'I':    /* initialize alias DBM file */
  643.             OpMode = MD_INITALIAS;
  644.             break;
  645. # endif DBM
  646.         }
  647.     }
  648.  
  649.     /*
  650.     **  Do basic initialization.
  651.     **    Read system control file.
  652.     **    Extract special fields for local use.
  653.     */
  654.  
  655.     if (OpMode == MD_FREEZE || readconfig)
  656.         readcf(ConfFile);
  657.  
  658.     switch (OpMode)
  659.     {
  660.       case MD_FREEZE:
  661.         /* this is critical to avoid forgeries of the frozen config */
  662.         (void) setgid(getgid());
  663.         (void) setuid(getuid());
  664.  
  665.         /* freeze the configuration */
  666.         freeze(FreezeFile);
  667.         exit(EX_OK);
  668.  
  669.       case MD_INITALIAS:
  670.         Verbose = TRUE;
  671.         break;
  672.     }
  673.  
  674.     /* do heuristic mode adjustment */
  675.     if (Verbose)
  676.     {
  677.         /* turn off noconnect option */
  678.         setoption('c', "F", TRUE, FALSE);
  679.  
  680.         /* turn on interactive delivery */
  681.         setoption('d', "", TRUE, FALSE);
  682.     }
  683.  
  684.     /* our name for SMTP codes */
  685.     expand("\001j", jbuf, &jbuf[sizeof jbuf - 1], CurEnv);
  686.     MyHostName = jbuf;
  687.  
  688.     /* the indices of local and program mailers */
  689.     st = stab("local", ST_MAILER, ST_FIND);
  690.     if (st == NULL)
  691.         syserr("No local mailer defined");
  692.     else
  693.         LocalMailer = st->s_mailer;
  694.     st = stab("prog", ST_MAILER, ST_FIND);
  695.     if (st == NULL)
  696.         syserr("No prog mailer defined");
  697.     else
  698.         ProgMailer = st->s_mailer;
  699.  
  700.     /* operate in queue directory */
  701.     if (chdir(QueueDir) < 0)
  702.     {
  703.         syserr("cannot chdir(%s)", QueueDir);
  704.         exit(EX_SOFTWARE);
  705.     }
  706.  
  707.     /*
  708.     **  Do operation-mode-dependent initialization.
  709.     */
  710.  
  711.     switch (OpMode)
  712.     {
  713.       case MD_PRINT:
  714.         /* print the queue */
  715. #ifdef QUEUE
  716.         dropenvelope(CurEnv);
  717.         printqueue();
  718.         exit(EX_OK);
  719. #else QUEUE
  720.         usrerr("No queue to print");
  721.         finis();
  722. #endif QUEUE
  723.  
  724.       case MD_INITALIAS:
  725.         /* initialize alias database */
  726.         initaliases(AliasFile, TRUE);
  727.         exit(EX_OK);
  728.  
  729.       case MD_DAEMON:
  730.         /* don't open alias database -- done in srvrsmtp */
  731.         break;
  732.  
  733.       default:
  734.         /* open the alias database */
  735.         initaliases(AliasFile, FALSE);
  736.         break;
  737.     }
  738.  
  739.     if (tTd(0, 15))
  740.     {
  741.         /* print configuration table (or at least part of it) */
  742.         printrules();
  743.         for (i = 0; i < MAXMAILERS; i++)
  744.         {
  745.             register struct mailer *m = Mailer[i];
  746.             int j;
  747.  
  748.             if (m == NULL)
  749.                 continue;
  750.             printf("mailer %d (%s): P=%s S=%d R=%d M=%ld F=", i, m->m_name,
  751.                 m->m_mailer, m->m_s_rwset, m->m_r_rwset,
  752.                 m->m_maxsize);
  753.             for (j = '\0'; j <= '\177'; j++)
  754.                 if (bitnset(j, m->m_flags))
  755.                     (void) putchar(j);
  756.             printf(" E=");
  757.             xputs(m->m_eol);
  758.             printf("\n");
  759.         }
  760.     }
  761.  
  762.     /*
  763.     **  Switch to the main envelope.
  764.     */
  765.  
  766.     CurEnv = newenvelope(&MainEnvelope);
  767.     MainEnvelope.e_flags = BlankEnvelope.e_flags;
  768.  
  769.     /*
  770.     **  If test mode, read addresses from stdin and process.
  771.     */
  772.  
  773.     if (OpMode == MD_TEST)
  774.     {
  775.         char buf[MAXLINE];
  776.  
  777.         printf("ADDRESS TEST MODE\nEnter <ruleset> <address>\n");
  778.         for (;;)
  779.         {
  780.             register char **pvp;
  781.             char *q;
  782.             extern char *DelimChar;
  783.  
  784.             printf("> ");
  785.             (void) fflush(stdout);
  786.             if (fgets(buf, sizeof buf, stdin) == NULL)
  787.                 finis();
  788.             for (p = buf; isspace(*p); p++)
  789.                 continue;
  790.             q = p;
  791.             while (*p != '\0' && !isspace(*p))
  792.                 p++;
  793.             if (*p == '\0')
  794.                 continue;
  795.             *p = '\0';
  796.             do
  797.             {
  798.                 extern char **prescan();
  799.                 char pvpbuf[PSBUFSIZE];
  800.  
  801.                 pvp = prescan(++p, ',', pvpbuf);
  802.                 if (pvp == NULL)
  803.                     continue;
  804.                 rewrite(pvp, 3);
  805.                 p = q;
  806.                 while (*p != '\0')
  807.                 {
  808.                     rewrite(pvp, atoi(p));
  809.                     while (*p != '\0' && *p++ != ',')
  810.                         continue;
  811.                 }
  812.             } while (*(p = DelimChar) != '\0');
  813.         }
  814.     }
  815.  
  816. # ifdef QUEUE
  817.     /*
  818.     **  If collecting stuff from the queue, go start doing that.
  819.     */
  820.  
  821.     if (queuemode && OpMode != MD_DAEMON && QueueIntvl == 0)
  822.     {
  823.         runqueue(FALSE);
  824.         finis();
  825.     }
  826. # endif QUEUE
  827.  
  828.     /*
  829.     **  If a daemon, wait for a request.
  830.     **    getrequests will always return in a child.
  831.     **    If we should also be processing the queue, start
  832.     **        doing it in background.
  833.     **    We check for any errors that might have happened
  834.     **        during startup.
  835.     */
  836.  
  837.     if (OpMode == MD_DAEMON || QueueIntvl != 0)
  838.     {
  839.         if (!tTd(0, 1))
  840.         {
  841.             /* put us in background */
  842.             i = fork();
  843.             if (i < 0)
  844.                 syserr("daemon: cannot fork");
  845.             if (i != 0)
  846.                 exit(0);
  847.  
  848.             /* get our pid right */
  849.             MotherPid = getpid();
  850.  
  851.             /* disconnect from our controlling tty */
  852.             disconnect(TRUE);
  853.         }
  854.  
  855. # ifdef QUEUE
  856.         if (queuemode)
  857.         {
  858.             runqueue(TRUE);
  859.             if (OpMode != MD_DAEMON)
  860.                 for (;;)
  861.                     pause();
  862.         }
  863. # endif QUEUE
  864.         dropenvelope(CurEnv);
  865.  
  866. #ifdef DAEMON
  867.         getrequests();
  868.  
  869.         /* at this point we are in a child: reset state */
  870.         OpMode = MD_SMTP;
  871.         (void) newenvelope(CurEnv);
  872.         openxscript(CurEnv);
  873. #endif DAEMON
  874.     }
  875.     
  876. # ifdef SMTP
  877.     /*
  878.     **  If running SMTP protocol, start collecting and executing
  879.     **  commands.  This will never return.
  880.     */
  881.  
  882.     if (OpMode == MD_SMTP)
  883.         smtp();
  884. # endif SMTP
  885.  
  886.     /*
  887.     **  Do basic system initialization and set the sender
  888.     */
  889.  
  890.     initsys();
  891.     setsender(from);
  892.  
  893.     if (OpMode != MD_ARPAFTP && *av == NULL && !GrabTo)
  894.     {
  895.         usrerr("Recipient names must be specified");
  896.  
  897.         /* collect body for UUCP return */
  898.         if (OpMode != MD_VERIFY)
  899.             collect(FALSE);
  900.         finis();
  901.     }
  902.     if (OpMode == MD_VERIFY)
  903.         SendMode = SM_VERIFY;
  904.  
  905.     /*
  906.     **  Scan argv and deliver the message to everyone.
  907.     */
  908.  
  909.     sendtoargv(av);
  910.  
  911.     /* if we have had errors sofar, arrange a meaningful exit stat */
  912.     if (Errors > 0 && ExitStat == EX_OK)
  913.         ExitStat = EX_USAGE;
  914.  
  915.     /*
  916.     **  Read the input mail.
  917.     */
  918.  
  919.     CurEnv->e_to = NULL;
  920.     if (OpMode != MD_VERIFY || GrabTo)
  921.         collect(FALSE);
  922.     errno = 0;
  923.  
  924.     /* collect statistics */
  925.     if (OpMode != MD_VERIFY)
  926.         markstats(CurEnv, (ADDRESS *) NULL);
  927.  
  928.     if (tTd(1, 1))
  929.         printf("From person = \"%s\"\n", CurEnv->e_from.q_paddr);
  930.  
  931.     /*
  932.     **  Actually send everything.
  933.     **    If verifying, just ack.
  934.     */
  935.  
  936.     CurEnv->e_from.q_flags |= QDONTSEND;
  937.     CurEnv->e_to = NULL;
  938.     sendall(CurEnv, SM_DEFAULT);
  939.  
  940.     /*
  941.     ** All done.
  942.     */
  943.  
  944.     finis();
  945. }
  946. /*
  947. **  FINIS -- Clean up and exit.
  948. **
  949. **    Parameters:
  950. **        none
  951. **
  952. **    Returns:
  953. **        never
  954. **
  955. **    Side Effects:
  956. **        exits sendmail
  957. */
  958.  
  959. finis()
  960. {
  961.     if (tTd(2, 1))
  962.         printf("\n====finis: stat %d e_flags %o\n", ExitStat, CurEnv->e_flags);
  963.  
  964.     /* clean up temp files */
  965.     CurEnv->e_to = NULL;
  966.     dropenvelope(CurEnv);
  967.  
  968.     /* post statistics */
  969.     poststats(StatFile);
  970.  
  971.     /* and exit */
  972. # ifdef LOG
  973.     if (LogLevel > 11)
  974.         syslog(LOG_DEBUG, "finis, pid=%d", getpid());
  975. # endif LOG
  976.     if (ExitStat == EX_TEMPFAIL)
  977.         ExitStat = EX_OK;
  978.     exit(ExitStat);
  979. }
  980. /*
  981. **  INTSIG -- clean up on interrupt
  982. **
  983. **    This just arranges to exit.  It pessimises in that it
  984. **    may resend a message.
  985. **
  986. **    Parameters:
  987. **        none.
  988. **
  989. **    Returns:
  990. **        none.
  991. **
  992. **    Side Effects:
  993. **        Unlocks the current job.
  994. */
  995.  
  996. intsig()
  997. {
  998.     FileName = NULL;
  999.     unlockqueue(CurEnv);
  1000.     exit(EX_OK);
  1001. }
  1002. /*
  1003. **  INITMACROS -- initialize the macro system
  1004. **
  1005. **    This just involves defining some macros that are actually
  1006. **    used internally as metasymbols to be themselves.
  1007. **
  1008. **    Parameters:
  1009. **        none.
  1010. **
  1011. **    Returns:
  1012. **        none.
  1013. **
  1014. **    Side Effects:
  1015. **        initializes several macros to be themselves.
  1016. */
  1017.  
  1018. struct metamac
  1019. {
  1020.     char    metaname;
  1021.     char    metaval;
  1022. };
  1023.  
  1024. struct metamac    MetaMacros[] =
  1025. {
  1026.     /* LHS pattern matching characters */
  1027.     '*', MATCHZANY,    '+', MATCHANY,    '-', MATCHONE,    '=', MATCHCLASS,
  1028.     '~', MATCHNCLASS,
  1029.  
  1030.     /* these are RHS metasymbols */
  1031.     '#', CANONNET,    '@@', CANONHOST,    ':', CANONUSER,    '>', CALLSUBR,
  1032.  
  1033.     /* the conditional operations */
  1034.     '?', CONDIF,    '|', CONDELSE,    '.', CONDFI,
  1035.  
  1036.     /* and finally the hostname lookup characters */
  1037.     '[', HOSTBEGIN,    ']', HOSTEND,
  1038.  
  1039.     '\0'
  1040. };
  1041.  
  1042. initmacros()
  1043. {
  1044.     register struct metamac *m;
  1045.     char buf[5];
  1046.     register int c;
  1047.  
  1048.     for (m = MetaMacros; m->metaname != '\0'; m++)
  1049.     {
  1050.         buf[0] = m->metaval;
  1051.         buf[1] = '\0';
  1052.         define(m->metaname, newstr(buf), CurEnv);
  1053.     }
  1054.     buf[0] = MATCHREPL;
  1055.     buf[2] = '\0';
  1056.     for (c = '0'; c <= '9'; c++)
  1057.     {
  1058.         buf[1] = c;
  1059.         define(c, newstr(buf), CurEnv);
  1060.     }
  1061. }
  1062. /*
  1063. **  FREEZE -- freeze BSS & allocated memory
  1064. **
  1065. **    This will be used to efficiently load the configuration file.
  1066. **
  1067. **    Parameters:
  1068. **        freezefile -- the name of the file to freeze to.
  1069. **
  1070. **    Returns:
  1071. **        none.
  1072. **
  1073. **    Side Effects:
  1074. **        Writes BSS and malloc'ed memory to freezefile
  1075. */
  1076.  
  1077. union frz
  1078. {
  1079.     char        frzpad[BUFSIZ];    /* insure we are on a BUFSIZ boundary */
  1080.     struct
  1081.     {
  1082.         time_t    frzstamp;    /* timestamp on this freeze */
  1083.         char    *frzbrk;    /* the current break */
  1084.         char    *frzedata;    /* address of edata */
  1085.         char    *frzend;    /* address of end */
  1086.         char    frzver[252];    /* sendmail version */
  1087.     } frzinfo;
  1088. };
  1089.  
  1090. freeze(freezefile)
  1091.     char *freezefile;
  1092. {
  1093.     int f;
  1094.     union frz fhdr;
  1095.     extern char edata, end;
  1096.     extern char *sbrk();
  1097.     extern char Version[];
  1098.  
  1099.     if (freezefile == NULL)
  1100.         return;
  1101.  
  1102.     /* try to open the freeze file */
  1103.     f = creat(freezefile, FileMode);
  1104.     if (f < 0)
  1105.     {
  1106.         syserr("Cannot freeze %s", freezefile);
  1107.         errno = 0;
  1108.         return;
  1109.     }
  1110.  
  1111.     /* build the freeze header */
  1112.     fhdr.frzinfo.frzstamp = curtime();
  1113.     fhdr.frzinfo.frzbrk = sbrk(0);
  1114.     fhdr.frzinfo.frzedata = &edata;
  1115.     fhdr.frzinfo.frzend = &end;
  1116.     (void) strcpy(fhdr.frzinfo.frzver, Version);
  1117.  
  1118.     /* write out the freeze header */
  1119.     if (write(f, (char *) &fhdr, sizeof fhdr) != sizeof fhdr ||
  1120.         write(f, (char *) &edata, (int) (fhdr.frzinfo.frzbrk - &edata)) !=
  1121.                     (int) (fhdr.frzinfo.frzbrk - &edata))
  1122.     {
  1123.         syserr("Cannot freeze %s", freezefile);
  1124.     }
  1125.  
  1126.     /* fine, clean up */
  1127.     (void) close(f);
  1128. }
  1129. /*
  1130. **  THAW -- read in the frozen configuration file.
  1131. **
  1132. **    Parameters:
  1133. **        freezefile -- the name of the file to thaw from.
  1134. **
  1135. **    Returns:
  1136. **        TRUE if it successfully read the freeze file.
  1137. **        FALSE otherwise.
  1138. **
  1139. **    Side Effects:
  1140. **        reads freezefile in to BSS area.
  1141. */
  1142.  
  1143. thaw(freezefile)
  1144.     char *freezefile;
  1145. {
  1146.     int f;
  1147.     union frz fhdr;
  1148.     extern char edata, end;
  1149.     extern char Version[];
  1150.     extern caddr_t brk();
  1151.  
  1152.     if (freezefile == NULL)
  1153.         return (FALSE);
  1154.  
  1155.     /* open the freeze file */
  1156.     f = open(freezefile, 0);
  1157.     if (f < 0)
  1158.     {
  1159.         syslog(LOG_WARNING, "Cannot open frozen config file %s: %m",
  1160.             freezefile);
  1161.         errno = 0;
  1162.         return (FALSE);
  1163.     }
  1164.  
  1165.     /* read in the header */
  1166.     if (read(f, (char *) &fhdr, sizeof fhdr) < sizeof fhdr)
  1167.     {
  1168.         syserr("Cannot read frozen config file");
  1169.         (void) close(f);
  1170.         return (FALSE);
  1171.     }
  1172.     if ( fhdr.frzinfo.frzedata != &edata ||
  1173.         fhdr.frzinfo.frzend != &end ||
  1174.         strcmp(fhdr.frzinfo.frzver, Version) != 0)
  1175.     {
  1176.         syslog(LOG_WARNING, "Wrong version of frozen config file");
  1177.         (void) close(f);
  1178.         return (FALSE);
  1179.     }
  1180.  
  1181.     /* arrange to have enough space */
  1182.     if (brk(fhdr.frzinfo.frzbrk) == (caddr_t) -1)
  1183.     {
  1184.         syserr("Cannot break to %x", fhdr.frzinfo.frzbrk);
  1185.         (void) close(f);
  1186.         return (FALSE);
  1187.     }
  1188.  
  1189.     /* now read in the freeze file */
  1190.     if (read(f, (char *) &edata, (int) (fhdr.frzinfo.frzbrk - &edata)) !=
  1191.                     (int) (fhdr.frzinfo.frzbrk - &edata))
  1192.     {
  1193.         syserr("Cannot read frozen config file");
  1194.         /* oops!  we have trashed memory..... */
  1195.         (void) write(2, "Cannot read freeze file\n", 24);
  1196.         _exit(EX_SOFTWARE);
  1197.     }
  1198.  
  1199.     (void) close(f);
  1200.     return (TRUE);
  1201. }
  1202. /*
  1203. **  DISCONNECT -- remove our connection with any foreground process
  1204. **
  1205. **    Parameters:
  1206. **        fulldrop -- if set, we should also drop the controlling
  1207. **            TTY if possible -- this should only be done when
  1208. **            setting up the daemon since otherwise UUCP can
  1209. **            leave us trying to open a dialin, and we will
  1210. **            wait for the carrier.
  1211. **
  1212. **    Returns:
  1213. **        none
  1214. **
  1215. **    Side Effects:
  1216. **        Trys to insure that we are immune to vagaries of
  1217. **        the controlling tty.
  1218. */
  1219.  
  1220. disconnect(fulldrop)
  1221.     bool fulldrop;
  1222. {
  1223.     int fd;
  1224.  
  1225.     if (tTd(52, 1))
  1226.         printf("disconnect: In %d Out %d\n", fileno(InChannel),
  1227.                         fileno(OutChannel));
  1228.     if (tTd(52, 5))
  1229.     {
  1230.         printf("don't\n");
  1231.         return;
  1232.     }
  1233.  
  1234.     /* be sure we don't get nasty signals */
  1235.     (void) signal(SIGHUP, SIG_IGN);
  1236.     (void) signal(SIGINT, SIG_IGN);
  1237.     (void) signal(SIGQUIT, SIG_IGN);
  1238.  
  1239.     /* we can't communicate with our caller, so.... */
  1240.     HoldErrs = TRUE;
  1241.     ErrorMode = EM_MAIL;
  1242.     Verbose = FALSE;
  1243.  
  1244.     /* all input from /dev/null */
  1245.     if (InChannel != stdin)
  1246.     {
  1247.         (void) fclose(InChannel);
  1248.         InChannel = stdin;
  1249.     }
  1250.     (void) freopen("/dev/null", "r", stdin);
  1251.  
  1252.     /* output to the transcript */
  1253.     if (OutChannel != stdout)
  1254.     {
  1255.         (void) fclose(OutChannel);
  1256.         OutChannel = stdout;
  1257.     }
  1258.     if (CurEnv->e_xfp == NULL)
  1259.         CurEnv->e_xfp = fopen("/dev/null", "w");
  1260.     (void) fflush(stdout);
  1261.     (void) close(1);
  1262.     (void) close(2);
  1263.     while ((fd = dup(fileno(CurEnv->e_xfp))) < 2 && fd > 0)
  1264.         continue;
  1265.  
  1266. #ifdef TIOCNOTTY
  1267.     /* drop our controlling TTY completely if possible */
  1268.     if (fulldrop)
  1269.     {
  1270.         fd = open("/dev/tty", 2);
  1271.         if (fd >= 0)
  1272.         {
  1273.             (void) ioctl(fd, (int) TIOCNOTTY, (char *) 0);
  1274.             (void) close(fd);
  1275.         }
  1276.         (void) setpgrp(0, 0);
  1277.         errno = 0;
  1278.     }
  1279. #endif TIOCNOTTY
  1280.  
  1281. # ifdef LOG
  1282.     if (LogLevel > 11)
  1283.         syslog(LOG_DEBUG, "in background, pid=%d", getpid());
  1284. # endif LOG
  1285.  
  1286.     errno = 0;
  1287. }
  1288. @
  1289.  
  1290.  
  1291. 5.29.0.1
  1292. log
  1293. @IDA patches
  1294. @
  1295. text
  1296. @d118 1
  1297. a118 1
  1298.     char jbuf[60];            /* holds MyHostName */
  1299. a125 1
  1300.     extern char *index();
  1301. d142 1
  1302. a142 1
  1303.     (void) unsetenv("TZ");
  1304. a143 3
  1305.     /* Make mail act uniformly (resolver recursion disabled elsewhere) */
  1306.     (void) unsetenv("HOSTALIASES");
  1307.  
  1308. a200 8
  1309.         else if (strncmp(p, "-Z", 2) == 0)
  1310.         {
  1311.             FreezeFile = &p[2];
  1312.             if (FreezeFile[0] == '\0')
  1313.                 FreezeFile = "sendmail.fc";
  1314.             (void) setgid(getrgid());
  1315.             (void) setuid(getruid());
  1316.         }
  1317. d205 1
  1318. a205 1
  1319.             setlinebuf(stdout);
  1320. a261 4
  1321.             if ((p = index(jbuf, '.')) != NULL)
  1322.                 *p = '\0';
  1323.             makelower(jbuf);
  1324.             define('k', newstr(jbuf), CurEnv);
  1325. a290 2
  1326.     else if (strcmp(p, "bsmtp") == 0)
  1327.         OpMode = MD_BSMTP;
  1328. d304 1
  1329. a310 1
  1330.               case MD_BSMTP:
  1331. a335 3
  1332.           case 'Z':    /* select frozen config file (already done) */
  1333.             break;
  1334.  
  1335. d339 1
  1336. a339 1
  1337.             setlinebuf(stdout);
  1338. a340 1
  1339.             if (tTd(8, 8))
  1340. d406 1
  1341. d518 1
  1342. a518 1
  1343.         initaliases(TRUE);
  1344. d527 1
  1345. a527 1
  1346.         initaliases(FALSE);
  1347. d542 3
  1348. a544 4
  1349.             printf("mailer %d (%s): P=%s S=%d/%d R=%d/%d M=%ld F=",
  1350.                 i, m->m_name, m->m_mailer,
  1351.                 m->m_se_rwset, m->m_sh_rwset,
  1352.                 m->m_re_rwset, m->m_rh_rwset, m->m_maxsize);
  1353. a569 1
  1354.         printf("[Note: No initial ruleset 3 call]\n");
  1355. d596 1
  1356. a596 1
  1357.                 /* rewrite(pvp, 3); */
  1358. d674 2
  1359. a675 11
  1360.     if (OpMode == MD_SMTP || OpMode == MD_BSMTP) {
  1361.         bool batched = (OpMode == MD_BSMTP);
  1362.         OpMode = MD_SMTP;
  1363. #ifdef notdef
  1364. /* test without this first */
  1365.         /* have to run unbuffered or else will lose synchronization */
  1366.         if (batched)
  1367.             setbuf(InChannel, (char *) NULL);
  1368. #endif notdef
  1369.         smtp(batched);
  1370.     }
  1371. d810 6
  1372. d828 1
  1373. a828 1
  1374.     /* and finally the hostname and database lookup characters */
  1375. a829 1
  1376.     '(', KEYBEGIN,    ')', KEYEND,
  1377. a830 7
  1378. #ifdef MACVALUE
  1379.     /* run-time macro expansion, not at freeze time */
  1380.     '&', MACVALUE,
  1381. #endif
  1382. #ifdef QUOTE822
  1383.     '!', QUOTE822,    /* quote next macro if RFC822 requires it */
  1384. #endif
  1385. a878 1
  1386.         char    frzdatecompiled[64];    /* sendmail compilation date */
  1387. a889 1
  1388.     extern char datecompiled[];
  1389. a908 1
  1390.     (void) strcpy(fhdr.frzinfo.frzdatecompiled, datecompiled);
  1391. a941 1
  1392.     extern char datecompiled[];
  1393. d966 1
  1394. a966 2
  1395.         strcmp(fhdr.frzinfo.frzver, Version) != 0 ||
  1396.         strcmp(fhdr.frzinfo.frzdatecompiled, datecompiled) != 0)
  1397. d1033 1
  1398. a1033 1
  1399.     setoption('e', "m", TRUE, TRUE);
  1400. @
  1401.  
  1402.  
  1403. 5.29.0.2
  1404. log
  1405. @Patches for HP-UX from Andy Linton <root@@comp.vuw.ac.nz>.  Thanks Andy!
  1406. @
  1407. text
  1408. @a141 1
  1409. #if !defined(hpux)
  1410. a143 1
  1411. #endif /* hpux */
  1412. a216 3
  1413. #if defined(hpux)
  1414.             setvbuf(stdout, (char *) NULL, _IOLBF, BUFSIZ);
  1415. #else
  1416. a217 1
  1417. #endif /* hpux */
  1418. a359 4
  1419.             tTflag(&p[2]);
  1420. #if defined(hpux)
  1421.                 setvbuf(stdout, (char *) NULL, _IOLBF, BUFSIZ);
  1422. #else
  1423. a360 1
  1424. #endif /* hpux */
  1425. @
  1426.  
  1427.  
  1428. 5.29.0.3
  1429. log
  1430. @Some syslog() and the openlog() calls were not #ifdef LOG.
  1431. @
  1432. text
  1433. @a161 1
  1434. #ifdef LOG
  1435. a166 1
  1436. #endif /* LOG */
  1437. a999 1
  1438. #ifdef LOG
  1439. a1001 1
  1440. #endif /* LOG */
  1441. a1017 1
  1442. #ifdef LOG
  1443. a1018 1
  1444. #endif /* LOG */
  1445. @
  1446.  
  1447.  
  1448. 5.29.0.4
  1449. log
  1450. @From: kessler@@hacketorium.Eng.Sun.COM (Tom Kessler)
  1451. Newsgroups: comp.bugs.4bsd,comp.mail.sendmail
  1452. Subject: bug in sendmail 5.64
  1453. Date: 11 Jul 90 20:52:35 GMT
  1454. Organization: Rocket Scientists Anonymous
  1455.  
  1456. In sendmail 5.64 a new field name q_ruser was added to the address structure
  1457. (found in sendmail.h).  The initialization of the variable NullAddress
  1458. (in main.c) was not updated to reflect this.  This can cause some problems
  1459. when you go to look at the q_host field or expect the q_ruser field to be
  1460. NULL.
  1461. @
  1462. text
  1463. @d81 1
  1464. a81 1
  1465.         { "", "", NULL, "" };
  1466. @
  1467.  
  1468.  
  1469. 5.29.0.5
  1470. log
  1471. @Use MAXHOSTNAMELEN from sys/param.h instead of a hardwired 64.  Provide
  1472. a default value for older systems.  Don't set FullName in either daemon
  1473. (-bd) or queue-run (-q) mode.  Unsetenv(LOCALDOMAIN) as well as
  1474. HOSTALIASES.  From suggestions by Charles Seeger, Neil Rickert, and
  1475. Mark D. Baushke.
  1476. @
  1477. text
  1478. @a38 4
  1479. #include <sys/param.h>
  1480. #ifndef MAXHOSTNAMELEN
  1481. # define MAXHOSTNAMELEN    64
  1482. #endif /* !MAXHOSTNAMELEN */
  1483. a115 1
  1484.     bool NoName = FALSE;
  1485. d118 1
  1486. a118 1
  1487.     char jbuf[MAXHOSTNAMELEN+1];    /* holds MyHostName */
  1488. a148 1
  1489.     (void) unsetenv("LOCALDOMAIN");
  1490. a208 2
  1491.         else if (strncmp(p, "-bd", 3) == 0 || strncmp(p, "-q", 2) == 0)
  1492.             NoName = TRUE;
  1493. d263 1
  1494. a263 1
  1495.     FullName = (NoName) ? NULL : getenv("NAME");
  1496. @
  1497.  
  1498.  
  1499. 5.29.0.6
  1500. log
  1501. @Changed delimiter character in prescan() call during address test mode (-bt)
  1502. to '\0' from ','.  Otherwise checking internal rulesets with comma
  1503. separated pieces becomes dicey.
  1504. @
  1505. text
  1506. @d637 1
  1507. a637 1
  1508.                 pvp = prescan(++p, '\0', pvpbuf);
  1509. @
  1510.  
  1511.  
  1512. 5.29.0.7
  1513. log
  1514. @Changes from Berkeley's 5.64 to 5.65 release (main.c, savemail.c, and
  1515. version.c)
  1516. @
  1517. text
  1518. @d28 1
  1519. a28 1
  1520. static char sccsid[] = "@@(#)main.c    5.31 (Berkeley) 7/20/90";
  1521. a32 1
  1522. #include <sys/param.h>
  1523. d46 1
  1524. a46 1
  1525. # endif /* lint */
  1526. d97 1
  1527. a97 1
  1528. # endif /* SETPROCTITLE */
  1529. d102 2
  1530. a103 2
  1531. #endif /* SMTP */
  1532. #endif /* DAEMON */
  1533. d173 1
  1534. a173 1
  1535. #endif /* LOG_MAIL */
  1536. d260 1
  1537. a260 1
  1538. # endif /* SETPROCTITLE */
  1539. d342 1
  1540. a342 1
  1541. # endif /* DAEMON */
  1542. d349 1
  1543. a349 1
  1544. # endif /* SMTP */
  1545. d385 1
  1546. a385 1
  1547. #endif /* NAMED_BIND */
  1548. d451 1
  1549. a451 1
  1550. # else /* !QUEUE */
  1551. d454 1
  1552. a454 1
  1553. # endif /* QUEUE */
  1554. d479 1
  1555. a479 1
  1556. # endif /* DBM */
  1557. d553 1
  1558. a553 1
  1559. #else /* !QUEUE */
  1560. d556 1
  1561. a556 1
  1562. #endif /* QUEUE */
  1563. d662 1
  1564. a662 1
  1565. # endif /* QUEUE */
  1566. d699 1
  1567. a699 1
  1568. # endif /* QUEUE */
  1569. d709 1
  1570. a709 1
  1571. #endif /* DAEMON */
  1572. d726 1
  1573. a726 1
  1574. #endif /* notdef */
  1575. d729 1
  1576. a729 1
  1577. # endif /* SMTP */
  1578. d820 1
  1579. a820 1
  1580. # endif /* LOG */
  1581. d882 1
  1582. a882 1
  1583. #endif /* MACVALUE */
  1584. d885 1
  1585. a885 1
  1586. #endif /* QUOTE822 */
  1587. d1122 1
  1588. a1125 4
  1589. #if BSD > 43
  1590.         daemon(1, 1);
  1591. #else /* BSD <= 43 */
  1592. #ifdef TIOCNOTTY
  1593. a1132 2
  1594. #endif /* TIOCNOTTY */
  1595. #endif /* BSD */
  1596. d1135 1
  1597. d1140 1
  1598. a1140 1
  1599. # endif /* LOG */
  1600. @
  1601.  
  1602.  
  1603. 5.29.0.8
  1604. log
  1605. @Neil Rickert's (rickert@@cs.niu.edu) res_init() fix.  Other bug fixes and
  1606. System 5 changes from Bruce Lilly (bruce%balilly@@sonyd1.broadcast.sony.com).
  1607. @
  1608. text
  1609. @d25 3
  1610. a28 3
  1611. # ifdef    __GNUC__
  1612. static    char    compiled[] = "@@(#)compiled by gcc version "__VERSION__;
  1613. # endif    /* __GNUC__ */
  1614. d33 2
  1615. d38 3
  1616. a40 5
  1617. #include <sys/file.h>
  1618. #ifdef NAMED_BIND
  1619. # include <arpa/nameser.h>
  1620. # include <resolv.h>
  1621. #endif /* NAMED_BIND */
  1622. d132 1
  1623. a250 5
  1624. #ifdef NAMED_BIND
  1625.     /* Make sure the resolver library is initialized */
  1626.     res_init();
  1627. #endif /* NAMED_BIND */
  1628.  
  1629. d770 4
  1630. a785 4
  1631.     /* collect statistics (done after sendall, since sendall may fork) */
  1632.     if (OpMode != MD_VERIFY)
  1633.         markstats(CurEnv, (ADDRESS *) NULL);
  1634.  
  1635. d1129 1
  1636. a1129 1
  1637. # ifdef TIOCNOTTY
  1638. d1137 1
  1639. a1137 1
  1640. # endif /* TIOCNOTTY */
  1641. a1138 5
  1642. #if !defined(BSD) && !defined(TIOCNOTTY) && defined(SYSTEM5)
  1643.         setpgrp();
  1644.         if (fork() != 0)
  1645.             exit(0);
  1646. #endif /* !BSD && !TIOCNOTTY && SYSTEM5 */
  1647. @
  1648.  
  1649.  
  1650. 5.29.0.9
  1651. log
  1652. @To: paul-pomes@@uiuc.edu
  1653. Subject: sendmail-5.65 incorrectly handles MX records with equal precedence
  1654. Date: Tue, 16 Oct 90 23:10:18 EDT
  1655. From: "David Edelsohn" <edelsohn@@nova.npac.syr.edu>
  1656.  
  1657. Description:
  1658.  
  1659.     I was just looking up the source to sendmail-5.61 to see why the
  1660. mail load is not being evenly distributed between my two hosts pointed to
  1661. by MX records with the same preference level.  In domain.c: getmxrr(), the
  1662. MX records are sorted by preference with a special case if the preferences
  1663. are identical.  The condition is as follows:
  1664.  
  1665.     if (prefer[i] > prefer[j] ||
  1666.         (prefer[i] == prefer[j] && rand() % 1 == 0)) {
  1667.             ...SWAP ENTRIES...
  1668.     }
  1669.  
  1670. Should not the test be (rand() & 01) or (rand() % 2)?  (rand() % 1) is
  1671. always 0!  rand() is not guaranteed to be random in the lowest bits as
  1672. random() is suppose to be, but even regularly alternating between swapping
  1673. and not swapping would be better than always swapping when preferences are
  1674. equal.
  1675.  
  1676.     Not only does rand() % 1 always return 0, not only does rand() & 1
  1677. alternate between 0 and 1 regularly at each call (as long as the load is
  1678. balanced it doesn't really matter), but since sendmail is called directly
  1679. by Mail, the random number generator is reset to the same value each time
  1680. (for both rand() and random()), i.e there is no call to srandom() with the
  1681. PID or time-of-day or some other seed.
  1682.     This appears to be the only use of a random number generator within
  1683. sendmail so only one MX record of equal precedence will be used assuming
  1684. that the records are always returned in the same order at each DNS resolver
  1685. call.  The only saving grace would be if a queued message has the MX host
  1686. re-calculated by the daemonized sendmail if the message is ever queued, but
  1687. with (rand % 1) this is irrelevent in sendmail-5.61.
  1688.  
  1689. Fix:
  1690.  
  1691.     1) Change "rand % 1" to "rand & 1"
  1692.     2) No matter which random number generator is used (rand() or
  1693. random()), use the appropriate seed initializer call during the initial
  1694. startup (in main.c?).  The seed must be set post-thaw.
  1695. @
  1696. text
  1697. @a275 1
  1698.     srand(MotherPid);
  1699. @
  1700.  
  1701.  
  1702. 5.29.0.10
  1703. log
  1704. @Added unixpc specific setbuf() call to unbuffer stdout.
  1705. @
  1706. text
  1707. @d231 1
  1708. a231 4
  1709. #else /* !hpux */
  1710. # if defined(unixpc)
  1711.             setbuf(stdout, (char *)NULL);
  1712. # else /* !unixpc */
  1713. a232 1
  1714. # endif /* unixpc */
  1715. d384 2
  1716. a385 5
  1717.             setvbuf(stdout, (char *) NULL, _IOLBF, BUFSIZ);
  1718. #else /* !hpux */
  1719. # if defined(unixpc)
  1720.             setbuf(stdout, (char *)NULL);
  1721. # else /* !unixpc */
  1722. a386 1
  1723. # endif /* unixpc */
  1724. @
  1725.  
  1726.  
  1727. 5.29.0.11
  1728. log
  1729. @Systems like Next machines don't have brk()/sbrk() so freeze()/thaw()
  1730. become no-ops #ifdef NeXT.  Made signal() usage more baroque.
  1731. @
  1732. text
  1733. @d271 1
  1734. a271 1
  1735.     if (signal(SIGINT, SIG_IGN) != (SIG_TYPE (*)()) SIG_IGN)
  1736. d273 1
  1737. a273 1
  1738.     if (signal(SIGHUP, SIG_IGN) != (SIG_TYPE (*)()) SIG_IGN)
  1739. a954 5
  1740. #if defined(NeXT)
  1741.     syserr("Cannot freeze %s on systems w.o. brk/sbrk", freezefile);
  1742.     errno = 0;
  1743.     return;
  1744. #else /* !NeXT */
  1745. a991 1
  1746. #endif /* NeXT */
  1747. a1009 4
  1748. #if defined(NeXT)
  1749.     errno = 0;
  1750.     return (FALSE);
  1751. #else /* !NeXT */
  1752. a1070 1
  1753. #endif /* NeXT */
  1754. @
  1755.  
  1756.  
  1757. 5.29.0.12
  1758. log
  1759. @Relocate IN_SCCS_ID
  1760. @
  1761. text
  1762. @a21 1
  1763. # define IN_SCCS_ID
  1764. d31 1
  1765. a31 1
  1766. #define _DEFINE
  1767. @
  1768.  
  1769.  
  1770. 5.29.0.13
  1771. log
  1772. @From: forys@@snake.utah.edu (Jeff Forys)
  1773. Newsgroups: comp.mail.sendmail
  1774. Date: 10 Nov 90 01:48:40 MST
  1775. Organization: University of Utah CS Dept
  1776. Subject: Sendmail 5.65 can loop on certain addresses +FIX
  1777.  
  1778. Index:    usr.lib/sendmail/src/parseaddr.c 4.3BSD
  1779.  
  1780. This applies to all known versions of sendmail (through "5.65").
  1781.  
  1782. Description:
  1783.     Sendmail reserves characters in the range 020 - 036 for coding
  1784.     its rewrite rules.  If one of these characters shows up in an
  1785.     address, the results are unpredictable (from a user's point of
  1786.     view).  Specifically, an address containing a "replacement on
  1787.     RHS" rule can cause sendmail to go into an infinite loop while
  1788.     processing various rewrite rules.
  1789.  
  1790.     I suppose this could be used for a denial-of-service attack;
  1791.     if an evil-minded person fired off a bunch of these in your
  1792.     direction, you would end up with an equal number of sendmail
  1793.     processes churning endlessly away on your CPU.  Of course,
  1794.     whence such an "attack" originates would be painfully obvious!
  1795. @
  1796. text
  1797. @a646 2
  1798.             if (invalidaddr(p+1))
  1799.                 continue;
  1800. @
  1801.  
  1802.  
  1803. 5.29.0.14
  1804. log
  1805. @Changed hpux to XPG3 (X-Open Portability Guide 3) that's set in sendmail.h.
  1806. From Andy Linton (andy.linton@@comp.vuw.ac.nz).
  1807. @
  1808. text
  1809. @d37 1
  1810. a164 3
  1811. #if defined(XPG3)
  1812.     for (i = (int) sysconf (_SC_OPEN_MAX); i > 2; --i)
  1813. #else
  1814. a165 1
  1815. #endif /* XPG3 */
  1816. d230 1
  1817. a230 1
  1818. #if defined(XPG3)
  1819. d232 1
  1820. a232 1
  1821. #else /* !XPG3 */
  1822. d238 1
  1823. a238 1
  1824. #endif /* XPG3 */
  1825. d256 1
  1826. a256 4
  1827.     /*
  1828.     ** Make sure the resolver library is initialized and that enough time
  1829.     ** is allowed for non-local servers.
  1830.     */
  1831. a257 1
  1832.     _res.retrans = 30;
  1833. d388 1
  1834. a388 1
  1835. #if defined(XPG3)
  1836. d390 1
  1837. a390 1
  1838. #else /* !XPG3 */
  1839. d396 1
  1840. a396 1
  1841. #endif /* XPG3 */
  1842. d1153 1
  1843. a1153 10
  1844. #if defined(XPG3)
  1845.     /*
  1846.      * setsid will provide a new session w/o any tty associated at all.
  1847.      * STANDARDS CONFORMANCE
  1848.      *     setpgrp: SVID2, XPG2
  1849.      *     setsid: XPG3, POSIX.1, FIPS 151-1
  1850.      */
  1851.     (void) setsid();
  1852. #else /* !XPG3 */
  1853. # if BSD > 43
  1854. d1155 2
  1855. a1156 2
  1856. # else /* BSD <= 43 */
  1857. #  ifdef TIOCNOTTY
  1858. d1164 3
  1859. a1166 3
  1860. #  endif /* TIOCNOTTY */
  1861. # endif /* BSD */
  1862. # if !defined(BSD) && !defined(TIOCNOTTY) && defined(SYSV)
  1863. d1170 1
  1864. a1170 2
  1865. # endif /* !BSD && !TIOCNOTTY && SYSV */
  1866. #endif /* XPG3 */
  1867. @
  1868.  
  1869.  
  1870. 5.29.0.15
  1871. log
  1872. @Freeze/thaw code now included only if _PATH_SENDMAILFC is #define'd in
  1873. pathnames.h .  Print the loadaverage for -d3.1.  Change intsig() declaration
  1874. to SIG_TYPE.
  1875. @
  1876. text
  1877. @d129 1
  1878. a129 1
  1879.     extern SIG_TYPE intsig();
  1880. a222 1
  1881. #ifdef _PATH_SENDMAILFC
  1882. a227 4
  1883. #else /* !_PATH_SENDMAILFC */
  1884.             /* Use printf since OutChannel isn't assigned yet */
  1885.             printf("Frozen configuration files not available\n");
  1886. #endif /* _PATH_SENDMAILFC */
  1887. a245 2
  1888.     if (tTd(3, 1))
  1889.         (void) getla();    /* prints load average in getla() */
  1890. a248 1
  1891. #ifdef _PATH_SENDMAILFC
  1892. a250 1
  1893. #endif /* _PATH_SENDMAILFC */
  1894. a516 1
  1895. #ifdef _PATH_SENDMAILFC
  1896. a523 4
  1897. #else /* !_PATH_SENDMAILFC */
  1898.         usrerr("Frozen configuration files not available");
  1899.         exit(EX_USAGE);
  1900. #endif /* _PATH_SENDMAILFC */
  1901. a864 1
  1902. SIG_TYPE
  1903. d933 1
  1904. a933 3
  1905.  
  1906. #ifdef _PATH_SENDMAILFC
  1907. /*
  1908. d965 5
  1909. d1007 1
  1910. d1026 4
  1911. d1044 1
  1912. a1044 1
  1913. # ifdef LOG
  1914. d1047 1
  1915. a1047 1
  1916. # endif /* LOG */
  1917. d1064 1
  1918. a1064 1
  1919. # ifdef LOG
  1920. d1066 1
  1921. a1066 1
  1922. # endif /* LOG */
  1923. d1091 1
  1924. a1092 1
  1925. #endif /* _PATH_SENDMAILFC */
  1926. @
  1927.  
  1928.  
  1929. 5.29.0.16
  1930. log
  1931. @NIS (nee YP) state is saved in the freeze, the readback of the freeze file
  1932. destroys similar information.  This causes strange results later due to the
  1933. unexpected closing of a file descriptor using a stale copy.
  1934.  
  1935. Roger D. Roles          rdr@@Alliant.COM
  1936. Rob McMahon        cudcv@@warwick.ac.uk
  1937. @
  1938. text
  1939. @a990 8
  1940. # ifdef YP
  1941.     {
  1942.         /*
  1943.          * NIS (nee YP) state is saved in the freeze, the readback
  1944.          * of the freeze file destroys similar information.  This
  1945.          * causes strange results later due to the unexpected closing
  1946.          * of a file descriptor using a stale copy.
  1947.          */
  1948. a991 6
  1949.         char *domain;
  1950.         if (yp_get_default_domain(&domain) == 0)
  1951.             yp_unbind(domain);
  1952.     }
  1953. # endif /* YP */
  1954.  
  1955. a1057 14
  1956. # ifdef YP
  1957.     {
  1958.         /*
  1959.          * NIS (nee YP) state is saved in the freeze, the readback
  1960.          * of the freeze file destroys similar information.  This
  1961.          * causes strange results later due to the unexpected closing
  1962.          * of a file descriptor using a stale copy.
  1963.          */
  1964.  
  1965.         char *domain;
  1966.         if (yp_get_default_domain(&domain) == 0)
  1967.             yp_unbind(domain);
  1968.     }
  1969. # endif /* YP */
  1970. @
  1971.  
  1972.  
  1973. 5.29.0.17
  1974. log
  1975. @Only reset the environment after a successful thaw.  Previously the
  1976. environment was always reset which used a lot of newstr() calls and
  1977. inflated the size of sendmail.fc.  Found by Piet Beertema (piet@@mcsun.eu.net).
  1978. @
  1979. text
  1980. @d257 3
  1981. d261 5
  1982. a265 9
  1983.     /* Reset the environment only after a successful thaw() */
  1984.     if (!nothaw && (readconfig = !thaw(FreezeFile)) == FALSE)
  1985.     {
  1986.         for (i = 0; i < MAXUSERENVIRON && envp[i] != NULL; i++)
  1987.             UserEnviron[i] = newstr(envp[i]);
  1988.         UserEnviron[i] = NULL;
  1989.         environ = UserEnviron;
  1990.     }
  1991. #endif /* _PATH_SENDMAILFC */
  1992. @
  1993.  
  1994.  
  1995. 5.29.0.18
  1996. log
  1997. @Deleted #include <sys/types.h> as it's already included via sendmail.h from
  1998. useful.h.  #include "sendmail.h" relocated to top of #include list.
  1999. @
  2000. text
  2001. @a33 1
  2002. #include "sendmail.h"
  2003. d36 1
  2004. @
  2005.  
  2006.  
  2007. 5.29.0.19
  2008. log
  2009. @End of environment incorrectly determined when frozen config file
  2010. not used.  Found by Piet Beertema.
  2011. @
  2012. text
  2013. @a265 3
  2014.     else
  2015.         for (i = 0; i < MAXUSERENVIRON && envp[i] != NULL; i++)
  2016.             ;
  2017. @
  2018.  
  2019.  
  2020. 5.29.0.20
  2021. log
  2022. @Added static keyword to declarations of intsig(), initmacros(), freeze(),
  2023. and thaw().
  2024. @
  2025. text
  2026. @d129 1
  2027. a129 2
  2028.     static SIG_TYPE intsig();
  2029.     static initmacros(), freeze(), thaw();
  2030. d883 1
  2031. a883 1
  2032. static SIG_TYPE
  2033. a931 1
  2034. static
  2035. a982 1
  2036. static
  2037. a1051 1
  2038. static
  2039. @
  2040.  
  2041.  
  2042. 5.29.0.21
  2043. log
  2044. @ANSIfied
  2045. @
  2046. text
  2047. @a48 12
  2048. #ifdef __STDC__
  2049. static void intsig();
  2050. static void initmacros();
  2051. static void freeze(const char *);
  2052. static thaw(const char *);
  2053. #else /* !__STDC__ */
  2054. static void intsig();
  2055. static void initmacros();
  2056. static void freeze();
  2057. static thaw();
  2058. #endif /* __STDC__ */
  2059.  
  2060. d113 1
  2061. d125 8
  2062. d677 1
  2063. a846 1
  2064. void
  2065. d884 1
  2066. a884 1
  2067. static void
  2068. d933 1
  2069. a933 1
  2070. static void
  2071. d985 1
  2072. a985 1
  2073. static void
  2074. d987 1
  2075. a987 1
  2076.     const char *freezefile;
  2077. d1057 1
  2078. a1057 1
  2079.     const char *freezefile;
  2080. a1153 1
  2081. void
  2082. @
  2083.  
  2084.  
  2085. 5.29.0.22
  2086. log
  2087. @Made UserEnviron a local variable that's set only when the environment
  2088. is copied (#if defined(SETPROCTITLE) && !defined(SYSV)).
  2089. @
  2090. text
  2091. @d45 1
  2092. a45 1
  2093. #ifdef lint
  2094. d47 1
  2095. a47 1
  2096. #endif /* lint */
  2097. d107 1
  2098. a107 1
  2099. #ifdef SETPROCTITLE
  2100. d110 1
  2101. a110 1
  2102. #endif /* SETPROCTITLE */
  2103. d113 1
  2104. a113 1
  2105. # ifndef SMTP
  2106. d115 1
  2107. a115 1
  2108. # endif /* SMTP */
  2109. a135 1
  2110.     char *UserEnviron[MAXUSERENVIRON+1];    /* saved user environment */
  2111. d170 1
  2112. a170 1
  2113. #else /* !XPG3 */
  2114. d177 1
  2115. a177 1
  2116. # ifdef LOG_MAIL
  2117. d179 1
  2118. a179 1
  2119. # else /* !LOG_MAIL */
  2120. d181 1
  2121. a181 1
  2122. # endif /* LOG_MAIL */
  2123. d261 2
  2124. a262 4
  2125.     /*
  2126.      * Copy the environment only if a successful thaw() is done
  2127.      * AND the environment will be munged later by setproctitle().
  2128.      */
  2129. a263 1
  2130. # if defined(SETPROCTITLE) && !defined(SYSV)
  2131. a271 1
  2132. # endif /* SETPROCTITLE && !SYSV */
  2133. d284 1
  2134. a284 1
  2135. #if defined(SETPROCTITLE) && !defined(SYSV)
  2136. d294 1
  2137. a294 1
  2138. #endif /* SETPROCTITLE && !SYSV */
  2139. d368 2
  2140. a369 3
  2141. #ifdef DAEMON
  2142.                 if (getuid() != 0)
  2143.                 {
  2144. d373 1
  2145. a373 1
  2146. #else /* !DAEMON */
  2147. d377 1
  2148. a377 1
  2149. #endif /* DAEMON */
  2150. d380 1
  2151. a380 1
  2152. #ifndef SMTP
  2153. d384 1
  2154. a384 1
  2155. #endif /* SMTP */
  2156. d483 2
  2157. a484 3
  2158. #ifdef QUEUE
  2159.             if (getuid() != 0)
  2160.             {
  2161. d490 1
  2162. a490 1
  2163. #else /* !QUEUE */
  2164. d493 1
  2165. a493 1
  2166. #endif /* QUEUE */
  2167. d514 1
  2168. a514 1
  2169. #ifdef DBM
  2170. d518 1
  2171. a518 1
  2172. #endif /* DBM */
  2173. d697 1
  2174. a697 1
  2175. #ifdef QUEUE
  2176. d707 1
  2177. a707 1
  2178. #endif /* QUEUE */
  2179. d736 1
  2180. a736 1
  2181. #ifdef QUEUE
  2182. d744 1
  2183. a744 1
  2184. #endif /* QUEUE */
  2185. d757 1
  2186. a757 1
  2187. #ifdef SMTP
  2188. d763 1
  2189. a763 2
  2190.     if (OpMode == MD_SMTP || OpMode == MD_BSMTP)
  2191.     {
  2192. d766 1
  2193. a766 1
  2194. # ifdef notdef
  2195. d771 1
  2196. a771 1
  2197. # endif /* notdef */
  2198. d774 1
  2199. a774 1
  2200. #endif /* SMTP */
  2201. d863 1
  2202. a863 1
  2203. #ifdef LOG
  2204. d866 1
  2205. a866 1
  2206. #endif /* LOG */
  2207. d1238 1
  2208. a1238 1
  2209. #ifdef LOG
  2210. d1241 1
  2211. a1241 1
  2212. #endif /* LOG */
  2213. @
  2214.  
  2215.  
  2216. 5.29.0.23
  2217. log
  2218. @Include <sys/signal.h>, not <signal.h>.  Hopefully the last go-around
  2219. on copying/not copying the environment.  It's now copied if a thaw()
  2220. succeeds and/or SETPROCTITLE is true.
  2221. @
  2222. text
  2223. @d35 1
  2224. a35 1
  2225. #include <sys/signal.h>
  2226. d50 1
  2227. a50 1
  2228. static SIG_TYPE intsig();
  2229. d55 1
  2230. a55 1
  2231. static SIG_TYPE intsig();
  2232. d261 1
  2233. d264 1
  2234. a264 1
  2235.      * and/or the environment will be munged later by setproctitle().
  2236. a265 1
  2237. #ifdef _PATH_SENDMAILFC
  2238. d267 1
  2239. a267 4
  2240. #else /* !_PATH_SENDMAILFC */
  2241.     if (!nothaw)
  2242. #endif /* _PATH_SENDMAILFC */
  2243. #if defined(SETPROCTITLE) && !defined(SYSV)
  2244. d276 1
  2245. a276 1
  2246. #endif /* SETPROCTITLE && !SYSV */
  2247. d278 1
  2248. d895 1
  2249. a895 1
  2250. static SIG_TYPE
  2251. @
  2252.  
  2253.  
  2254. 5.29.0.24
  2255. log
  2256. @Character set translation changes adapted from patches from Keld Simonsen
  2257. (keld@@dkuug.dk).
  2258. @
  2259. text
  2260. @a536 4
  2261. #ifdef BIT8
  2262.     ascii = getchset("ASCII", 29);
  2263. #endif /* BIT8 */
  2264.  
  2265. @
  2266.  
  2267.  
  2268. 5.29.0.25
  2269. log
  2270. @Added RCS ID string
  2271. @
  2272. text
  2273. @a26 1
  2274. static char  rcsid[] = "@@(#)$Id$";
  2275. @
  2276.  
  2277.  
  2278. 5.29.0.26
  2279. log
  2280. @Added new relatives of -q command line flag:  -Sfoo runs only those
  2281. queued messages with "foo" in the sender string, -Rfoo runs only those
  2282. that have foo in the recipient string, and -MAA07305 runs only the
  2283. message with the ID AA07305.  From patches adapted from Peter J Nilsson
  2284. (pjn@@ida.liu.se).
  2285. @
  2286. text
  2287. @d27 1
  2288. a27 1
  2289. static char  rcsid[] = "@@(#)$Id: main.c,v 5.29.0.25 1991/04/05 14:55:15 paul Exp paul $";
  2290. a95 3
  2291. char        *MatchRecipient;/* for selective queue runs on Recipients */
  2292. char        *MatchSender;    /* for selective queue runs on Senders */
  2293. char        *QueueID;    /* run a certain message in the queue */
  2294. a369 2
  2295.         char    c;
  2296.  
  2297. a491 3
  2298.           case 'R':    /* run queued messages matching pattern */
  2299.           case 'S':    /* run queued messages matching pattern */
  2300.           case 'M':    /* run queue message with this queue ID */
  2301. a492 4
  2302.           {
  2303.             char c = p[1];
  2304.  
  2305.             p += 2;
  2306. a497 16
  2307.             if (queuemode)
  2308.             {
  2309.                     usrerr("Use only one of -q, -R, -S, and -M");
  2310.                 exit (EX_USAGE);
  2311.             }
  2312.             if (c != 'q')
  2313.             {
  2314.                 if (*p == '\0' && ((p = *++av) == NULL || 
  2315.                     *p == '-'))
  2316.                 {
  2317.                     usrerr("Bad -%c flag", c);
  2318.                     ExitStat = EX_USAGE;
  2319.                     av--;
  2320.                     break;
  2321.                 }
  2322.             }
  2323. d499 1
  2324. a499 19
  2325.             switch (c)
  2326.             {
  2327.               case 'q':
  2328.                 QueueIntvl = convtime(p);
  2329.                 break;
  2330.  
  2331.               case 'R':
  2332.                 MatchRecipient = newstr(p);
  2333.                 break;
  2334.  
  2335.               case 'S':
  2336.                 MatchSender = newstr(p);
  2337.                 break;
  2338.  
  2339.               case 'M':
  2340.                 QueueID = newstr(p);
  2341.                 break;
  2342.             }
  2343.           }
  2344. d539 1
  2345. a539 5
  2346.     {
  2347.         char    *abuf = newstr("ASCII");
  2348.         ascii = getchset(abuf, 29);
  2349.         (void) free(abuf);
  2350.     }
  2351. @
  2352.  
  2353.  
  2354. 5.29.0.27
  2355. log
  2356. @System 5 and general improvement patches contributed by Bruce Lilly
  2357. (bruce%balilly@@broadcast.sony.com).
  2358. @
  2359. text
  2360. @a22 1
  2361. # define _DEFINE
  2362. d26 2
  2363. a27 2
  2364. static char sccsid[] = "@@(#)main.c    5.31 (Berkeley) 7/20/90    %I% local";
  2365. static char  rcsid[] = "@@(#)$Id: main.c,v 5.29.0.26 1991/04/11 15:11:47 paul Exp paul $";
  2366. d33 2
  2367. a44 3
  2368. #ifdef SYSV
  2369. # include <sys/utsname.h>
  2370. #endif /* SYSV */
  2371. d47 1
  2372. a47 1
  2373. int    edata, end;
  2374. d53 2
  2375. a54 2
  2376. static void freeze(char *);
  2377. static thaw(char *);
  2378. a121 1
  2379. void
  2380. a330 3
  2381. #ifdef SYSV
  2382.             struct    utsname    utsname;
  2383. #endif /* SYSV */
  2384. a338 14
  2385. #ifdef SYSV
  2386.             if ((uname(&utsname) != -1) &&
  2387.                 strncmp(utsname.nodename, jbuf, 8))
  2388.             {
  2389.                 define('k', newstr(utsname.nodename), CurEnv);
  2390.                 if (tTd(0, 4))
  2391.                     printf("UUCP nodename: %s\n",
  2392.                         utsname.nodename);
  2393. # ifdef LOG
  2394.                 syslog(LOG_NOTICE, "UUCP nodename (%s) and lowest level of canonical name (%s) differ",
  2395.                     utsname.nodename, jbuf);
  2396. # endif /* LOG */
  2397.             } else
  2398. #endif /* SYSV */
  2399. d1055 1
  2400. a1055 1
  2401.     char *freezefile;
  2402. d1059 1
  2403. a1059 1
  2404.     extern int edata, end;
  2405. d1093 2
  2406. a1094 2
  2407.     fhdr.frzinfo.frzedata = (char *) &edata;
  2408.     fhdr.frzinfo.frzend = (char *) &end;
  2409. d1100 2
  2410. a1101 2
  2411.         write(f, (char *) &edata, (int) (fhdr.frzinfo.frzbrk - (char *) &edata)) !=
  2412.                     (int) (fhdr.frzinfo.frzbrk - (char *) &edata))
  2413. d1123 1
  2414. a1123 1
  2415. static int
  2416. d1125 1
  2417. a1125 1
  2418.     char *freezefile;
  2419. d1129 1
  2420. a1129 1
  2421.     extern int edata, end;
  2422. d1170 2
  2423. a1171 2
  2424.     if ( fhdr.frzinfo.frzedata != (char *) &edata ||
  2425.         fhdr.frzinfo.frzend != (char *) &end ||
  2426. d1191 2
  2427. a1192 2
  2428.     if (read(f, (char *) &edata, (int) (fhdr.frzinfo.frzbrk - (char *) &edata)) !=
  2429.                     (int) (fhdr.frzinfo.frzbrk - (char *) &edata))
  2430. @
  2431.  
  2432.  
  2433. 5.29.0.28
  2434. log
  2435. @Changed unixpc definitions to more general SYSV ones.
  2436. @
  2437. text
  2438. @d28 1
  2439. a28 1
  2440. static char  rcsid[] = "@@(#)$Id: main.c,v 5.29.0.27 1991/05/18 17:30:34 paul Exp paul $";
  2441. d35 1
  2442. d253 1
  2443. a253 1
  2444. # if defined(SYSV)
  2445. d255 1
  2446. a255 1
  2447. # else /* !SYSV */
  2448. d257 1
  2449. a257 1
  2450. # endif /* SYSV */
  2451. d449 1
  2452. a449 1
  2453. # if defined(SYSV)
  2454. d451 1
  2455. a451 1
  2456. # else /* !SYSV */
  2457. d453 1
  2458. a453 1
  2459. # endif /* SYSV */
  2460. @
  2461.  
  2462.  
  2463. 5.29.0.29
  2464. log
  2465. @First pass at adding Bruce Lilly's database auto-build code.
  2466. @
  2467. text
  2468. @d28 1
  2469. a28 1
  2470. static char  rcsid[] = "@@(#)$Id: main.c,v 5.29.0.28 1991/05/23 21:39:05 paul Exp paul $";
  2471. a694 1
  2472. #if !defined(DBM_AUTOBUILD) || ( !defined(NDBM) && !defined(OTHERDBM) )
  2473. a696 1
  2474. #endif /* !DBM_AUTOBUILD || (!NDBM && !OTHERDBM) */
  2475. @
  2476.  
  2477.  
  2478. 5.29.0.30
  2479. log
  2480. @Re-vamped save of user environment (again), fixed some type mis-matches,
  2481. moved debug call of getla() after the thaw.
  2482. @
  2483. text
  2484. @d28 1
  2485. a28 1
  2486. static char  rcsid[] = "@@(#)$Id: main.c,v 5.29.0.30 1991/05/29 13:48:54 paul Exp $";
  2487. a43 1
  2488. # undef newstr    /* a structure name in sys/utsname.h under RT/AIX */
  2489. a44 1
  2490. # define newstr(s)    strcpy(xalloc(strlen(s) + 1), s)
  2491. d262 2
  2492. d272 2
  2493. a274 1
  2494.         readconfig = !thaw(FreezeFile);
  2495. d276 20
  2496. a297 5
  2497.     for (i = 0; i < MAXUSERENVIRON && envp[i] != NULL; i++)
  2498.         UserEnviron[i] = newstr(envp[i]);
  2499.     UserEnviron[i] = NULL;
  2500.     environ = UserEnviron;
  2501.  
  2502. a308 9
  2503. #ifdef NAMED_BIND
  2504.     /*
  2505.     ** Make sure the resolver library is initialized and that enough time
  2506.     ** is allowed for non-local servers.
  2507.     */
  2508.     res_init();
  2509.     _res.retrans = 30;
  2510. #endif /* NAMED_BIND */
  2511.  
  2512. a732 3
  2513.     if (tTd(3, 1))
  2514.         (void) getla();    /* prints load average in getla() */
  2515.  
  2516. d852 2
  2517. a853 1
  2518.  
  2519. d857 1
  2520. d1191 4
  2521. a1195 15
  2522.         char why[40];
  2523.  
  2524.         *why = '\0';
  2525.         if (fhdr.frzinfo.frzedata != (char *) &edata)
  2526.             (void) strcat(why, "Edata");
  2527.         if (fhdr.frzinfo.frzend != (char *) &end)
  2528.             (void) strcat(why, "End");
  2529.         if (strcmp(fhdr.frzinfo.frzver, Version))
  2530.             (void) strcat(why, "Version");
  2531.         if (strcmp(fhdr.frzinfo.frzdatecompiled, datecompiled))
  2532.             (void) strcat(why, "Datecompiled");
  2533.         if (*why)
  2534.         {
  2535.             if (tTd(0, 1))
  2536.                 printf("Wrong version of frozen config file (%s mismatch)\n", why);
  2537. d1197 1
  2538. a1197 1
  2539.             syslog(LOG_WARNING, "Wrong version of frozen config file (%s mismatch)", why);
  2540. d1199 2
  2541. a1200 3
  2542.             (void) close(f);
  2543.             return (FALSE);
  2544.         }
  2545. @
  2546.  
  2547.  
  2548. 5.29.0.31
  2549. log
  2550. @(void) free() is bogus.
  2551. @
  2552. text
  2553. @d28 1
  2554. a28 1
  2555. static char  rcsid[] = "@@(#)$Id: main.c,v 5.29.0.30 1991/06/02 03:38:40 paul Exp paul $";
  2556. d600 1
  2557. a600 1
  2558.         free(abuf);
  2559. @
  2560.  
  2561.  
  2562. 5.29.0.32
  2563. log
  2564. @Use TIME_TYPE instead of time_t.  Use HAS_UNAME wrapper around uname()
  2565. calls instead of SYSV.  Comment out the unsetenv(TZ) call.  Added commented
  2566. out code block to print command line arguments.  Further ANSIfications added.
  2567. Hideous hack inserted into -M processing to set macro values ala DEC's
  2568. sendmail.  Also:
  2569.  
  2570. From comp.mail.sendmail Fri Jun 21 08:42:16 1991
  2571. From: sjg@@melb.bull.oz.au (Simon J Gerraty)
  2572. Newsgroups: comp.mail.sendmail
  2573. Subject: Re: LHS map lookup. Missing feature in IDA sendmail?
  2574. Date: 4 Jun 91 05:24:09 GMT
  2575. Organization: Bull HN Information Systems Australia.
  2576.  
  2577. The $(x key $@@ arg $: default $) feature is _just_ what I have
  2578. always wanted on the RHS of a re-write rule.
  2579.  
  2580. However I am used to having Sun's $%x and $!x features for
  2581. checking a key in a map in the LHS of the rules.
  2582.  
  2583. Implementing $%x and $!x on LHS
  2584.  
  2585. Unfortunately $!x is used on the RHS by the QUOTE822 facility.
  2586. [Added as $^x  -pbp]
  2587.  
  2588. For those unfamiliar but curious a LHS pattern like:
  2589.  
  2590. R$*<@@$%Y>$*
  2591.  
  2592. Matches if the tokens within `<>' can be found as a key in
  2593. the DBM map Y.  If the map is declared with OKY%map vs
  2594. OKYmap, then Yellow Pages (NIS) is used.
  2595. @
  2596. text
  2597. @d27 2
  2598. a28 2
  2599. static char sccsid[] = "@@(#)main.c    5.31 (Berkeley) 7/20/90";
  2600. static char  rcsid[] = "@@(#)$Id: main.c,v 5.29.0.31 1991/06/13 20:18:58 paul Exp paul $";
  2601. d43 1
  2602. a43 1
  2603. #ifdef HAS_UNAME
  2604. d47 1
  2605. a47 1
  2606. #endif /* HAS_UNAME */
  2607. a143 1
  2608. #if defined(SETPROCTITLE) && !defined(SYSV)
  2609. a145 1
  2610. #endif /* SETPROCTITLE && !SYSV */
  2611. d160 1
  2612. a160 1
  2613. #if defined(notdef) && !defined(SYSV)
  2614. d163 1
  2615. a163 1
  2616. #endif /* notdef && !SYSV */
  2617. a207 18
  2618.     argv[argc] = NULL;
  2619. #ifdef notdef
  2620.     /* Print the argument list when debugging */
  2621.     {
  2622.         char    *cmdline = xalloc(MAXLINE);
  2623.  
  2624.         for (*cmdline = '\0', av = argv; *av; av++)
  2625.         {
  2626.             (void) strcat(cmdline, *av);
  2627.             (void) strcat(cmdline, " ");
  2628.         }
  2629.         syslog(LOG_DEBUG, "Invoked as: %s", cmdline);
  2630.         free(cmdline);
  2631.     }
  2632. #endif /* notdef */
  2633.     av = argv;
  2634.     nothaw = FALSE;
  2635.  
  2636. d215 4
  2637. d326 1
  2638. a326 1
  2639. #ifdef HAS_UNAME
  2640. d328 1
  2641. a328 1
  2642. #endif /* HAS_UNAME */
  2643. d337 1
  2644. a337 1
  2645. #ifdef HAS_UNAME
  2646. d350 1
  2647. a350 1
  2648. #endif /* HAS_UNAME */
  2649. d385 2
  2650. a511 8
  2651.                 /* or if 'a' < p[2] <= 'z', set the macro */
  2652.                 /* this is worse than hideous, blame DECnet */
  2653.             if (p[1] == 'M' && p[2] != '\0' && islower(p[2]) &&
  2654.                 p[2] > 'a')
  2655.             {
  2656.                 setoption(p[1], &p[2], FALSE, TRUE);
  2657.                 break;
  2658.             }
  2659. d994 1
  2660. a994 1
  2661.     '~', MATCHNCLASS,        '%', MATCHMAP,    '^', MATCHNMAP,        
  2662. d1059 1
  2663. a1059 1
  2664.         TIME_TYPE frzstamp;    /* timestamp on this freeze */
  2665. a1074 3
  2666. #ifdef __STDC__
  2667.     extern void *sbrk(int);
  2668. #else /* !__STDC__ */
  2669. a1075 1
  2670. #endif /* __STDC__ */
  2671. d1147 1
  2672. a1147 5
  2673. #ifdef __STDC__
  2674.     extern int brk(void *);
  2675. #else /* !__STDC__ */
  2676.     extern int brk();
  2677. #endif /* __STDC__ */
  2678. d1210 1
  2679. a1210 1
  2680.     if (brk(fhdr.frzinfo.frzbrk) == -1)
  2681. @
  2682.  
  2683.  
  2684. 5.29.0.33
  2685. log
  2686. @Revised special case include of utsname.h under RT/AIX.
  2687. @
  2688. text
  2689. @d28 1
  2690. a28 1
  2691. static char  rcsid[] = "@@(#)$Id: main.c,v 5.29.0.32 1991/06/21 13:58:10 paul Exp paul $";
  2692. a33 4
  2693. #ifdef AIX
  2694. # include <sys/utsname.h>
  2695. # undef newstr    /* a structure name in sys/utsname.h under RT/AIX */
  2696. #endif /* AIX */
  2697. a34 3
  2698. #if defined(HAS_UNAME) && !defined(AIX)
  2699. # include <sys/utsname.h>
  2700. #endif /* HAS_UNAME && !AIX */
  2701. d43 5
  2702. @
  2703.  
  2704.  
  2705. 5.29.0.34
  2706. log
  2707. @Downgraded missing sendmail.fc from LOG_WARNING to LOG_NOTICE.
  2708. @
  2709. text
  2710. @d28 1
  2711. a28 1
  2712. static char  rcsid[] = "@@(#)$Id: main.c,v 5.29.0.33 1991/06/25 05:25:13 paul Exp paul $";
  2713. d1189 1
  2714. a1189 1
  2715.         syslog(LOG_NOTICE, "Cannot open frozen config file %s: %m",
  2716. @
  2717.  
  2718.  
  2719. 5.29.0.35
  2720. log
  2721. @Moved debug block that reports command line arguments to after the freeze()
  2722. of the sendmail.fc file.  Using syslog() prior to a freeze() sets a syslog
  2723. state variable that's not saved or restored.
  2724. @
  2725. text
  2726. @d28 1
  2727. a28 1
  2728. static char  rcsid[] = "@@(#)$Id: main.c,v 5.29.0.34 1991/06/27 14:24:13 paul Exp paul $";
  2729. d213 14
  2730. d363 5
  2731. a367 2
  2732.             }
  2733.             else
  2734. a651 18
  2735. #ifdef notdef
  2736.     /*
  2737.      * Print the argument list when debugging.  This has to come after the
  2738.      * freeze() statement as the first syslog() call sets a state variable
  2739.      * that won't get saved or restored.
  2740.      */
  2741.     {
  2742.         char    *cmdline = xalloc(MAXLINE);
  2743.  
  2744.         for (*cmdline = '\0', av = argv; *av; av++)
  2745.         {
  2746.             (void) strcat(cmdline, *av);
  2747.             (void) strcat(cmdline, " ");
  2748.         }
  2749.         syslog(LOG_DEBUG, "Invoked as: %s", cmdline);
  2750.         free(cmdline);
  2751.     }
  2752. #endif /* notdef */
  2753. @
  2754.  
  2755.  
  2756. 5.29.0.36
  2757. log
  2758. @Date:    Wed, 31 Jul 91 13:24:05 -0500
  2759. To:      Paul Pomes <Paul-Pomes@@uiuc.edu>
  2760. cc:      "Mark D. Baushke" <mdb@@esd.3com.com>
  2761. From:    Neil Rickert <rickert@@cs.niu.edu>
  2762. Subject: patches / bugs in sendmail-IDA.
  2763.  
  2764. I am enclosing the patch I prepared for a few users who were having problems
  2765. with frozen config files on Suns, in spite of static linking and using
  2766. ../uiuc/malloc.c .
  2767.  
  2768. It eliminates any code that even smells of YP/NIS prior to the completion of
  2769. freeze/thaw operations.
  2770.  
  2771. It is probably safe, and perhaps even desirable, to remove the yp_unbind()
  2772. calls from main.c
  2773.  
  2774.  -Neil
  2775. @
  2776. text
  2777. @d28 1
  2778. a28 1
  2779. static char  rcsid[] = "@@(#)$Id: main.c,v 5.29.0.35 1991/08/05 22:12:40 paul Exp paul $";
  2780. a652 16
  2781.  
  2782.     /*
  2783.      *    The call to setdefuser() is moved from readcf.c to here.
  2784.      *    The result is only used in deliver.c, so delaying it until
  2785.      *    now should be safe.
  2786.      *
  2787.      *    The function setdefuser() looks up the passwd database.  In
  2788.      *    some systems, notably Suns, this may involve a YP lookup.
  2789.      *    Unfortunately YP lookups leave behind some state information
  2790.      *    which seems to be incompatible with the freeze/thaw operations.
  2791.      *
  2792.      *    Placing the call here delays it till after the freeze/thaw
  2793.      *    is complete.
  2794.      */
  2795.     setdefuser();
  2796.  
  2797. d1110 1
  2798. a1110 1
  2799. # ifdef notdef
  2800. d1196 1
  2801. a1196 1
  2802. # ifdef notdef
  2803. @
  2804.